#include "KSADPrimaryGeneratorMessenger.hh"
#include "KSADPrimaryGeneratorAction.hh"
#include "G4UIcommand.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithADouble.hh"
#include "G4UIcmdWithAString.hh"

KSADPrimaryGeneratorMessenger::KSADPrimaryGeneratorMessenger(KSADPrimaryGeneratorAction *inputAction)	// Initialize all Cmds
{
	action = inputAction;	// Take KSADPrimaryGeneratorAction pointer as argument to access later
	
	mainDirectory = new G4UIdirectory("/KSAD/");
	mainDirectory->SetGuidance("Contains commands for controlling KSAD defined aspects of the particle beam and data output.");
	
	polarAngleCmd = new G4UIcmdWithADoubleAndUnit("/KSAD/polarAngle",this);
	polarAngleCmd->SetGuidance("Polar angle of ray gun (angle units)");
	polarAngleCmd->SetParameterName("polarAngle",false,false);
	polarAngleCmd->SetDefaultUnit("deg");
	polarAngleCmd->SetUnitCandidates("radian deg");

	azimuthalAngleCmd = new G4UIcmdWithADoubleAndUnit("/KSAD/azimuthalAngle",this);
	azimuthalAngleCmd->SetGuidance("Azimuthal angle of ray gun (angle units)");
	azimuthalAngleCmd->SetParameterName("azimuthalAngle",false,false);
	azimuthalAngleCmd->SetDefaultUnit("deg");
	azimuthalAngleCmd->SetUnitCandidates("radian deg");

	startCrystalICmd = new G4UIcmdWithAnInteger("/KSAD/startCrystalI",this);
	startCrystalICmd->SetGuidance("Give integer for crystal i position");
	startCrystalICmd->SetParameterName("startCrystalI",false,false);

	startCrystalJCmd = new G4UIcmdWithAnInteger("/KSAD/startCrystalJ",this);
	startCrystalJCmd->SetGuidance("Give integer for crystal j position");
	startCrystalJCmd->SetParameterName("startCrystalJ",false,false);

	PFCKCmd = new G4UIcmdWithADoubleAndUnit("/KSAD/PFCK",this);
	PFCKCmd->SetGuidance("Distance from crystals in k direction, give value and units");
	PFCKCmd->SetParameterName("PFCK",false,false);
	PFCKCmd->SetDefaultUnit("cm");
	PFCKCmd->SetUnitCandidates("m cm mm nm");

	PFCICmd = new G4UIcmdWithADouble("/KSAD/PFCI",this);
	PFCICmd->SetGuidance("Distance from center of startCrystal in i direction in units of crystalSize");
	PFCICmd->SetParameterName("PFCI",false,false);

	PFCJCmd = new G4UIcmdWithADouble("/KSAD/PFCJ",this);
	PFCJCmd->SetGuidance("Distance from center of startCrystal in j direction in units of crystalSize");
	PFCJCmd->SetParameterName("PFCJ",false,false);
}

KSADPrimaryGeneratorMessenger::~KSADPrimaryGeneratorMessenger()
{
	delete mainDirectory;
	delete polarAngleCmd;
	delete azimuthalAngleCmd;
	delete startCrystalICmd;
	delete startCrystalJCmd;
	delete PFCICmd;
	delete PFCJCmd;
	delete PFCKCmd;
}

void KSADPrimaryGeneratorMessenger::SetNewValue(G4UIcommand *inputCommand, G4String inputString)	// Recognize input Cmd and call appropriate method of
{													// KSADPrimaryGeneratorAction
	if(inputCommand == polarAngleCmd)
	{
		action->setPolarAngle(polarAngleCmd->GetNewDoubleValue(inputString));
	}
	else if(inputCommand == azimuthalAngleCmd)
	{
		action->setAzimuthalAngle(azimuthalAngleCmd->GetNewDoubleValue(inputString));
	}
	else if(inputCommand == startCrystalICmd)
	{
		action->setStartCrystalI(startCrystalICmd->GetNewIntValue(inputString));
	}
	else if(inputCommand == startCrystalJCmd)
	{
		action->setStartCrystalJ(startCrystalJCmd->GetNewIntValue(inputString));
	}
	else if(inputCommand == PFCICmd)
	{
		action->setPFCI(PFCICmd->GetNewDoubleValue(inputString));
	}
	else if(inputCommand == PFCJCmd)
	{
		action->setPFCJ(PFCJCmd->GetNewDoubleValue(inputString));
	}
	else if(inputCommand == PFCKCmd)
	{
		action->setPFCK(PFCKCmd->GetNewDoubleValue(inputString));
	}
}

G4String KSADPrimaryGeneratorMessenger::GetCurrentValue(G4UIcommand*)	// Returns blank string for any Cmd, G4Person *me = new LazyPerson;
{
	return "";
}
